package com.cynteka.cyfoman.ui.collection;

import com.cynteka.cyfoman.ui.StrippedTable;

import javax.swing.table.TableCellRenderer;
import java.awt.*;

/**
 * User: Sergey
 * Date: 04.08.11
 * Time: 18:26
 */
public class CollectionTable extends StrippedTable {
    @Override
    public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
        Component component = super.prepareRenderer(renderer, row, column);

        CollectionTableModel model = (CollectionTableModel) getModel();
        int modelRow = convertRowIndexToModel(row);
        Color bgColor = (Color) model.getValue(modelRow, ColorFontChooserPropertyResolver.BACKGROUND_COLOR_PN);
        if(bgColor != null) {
            component.setBackground(bgColor);
        }

        Color color = (Color) model.getValue(modelRow, ColorFontChooserPropertyResolver.COLOR_PN);
        if(color != null) {
            component.setForeground(color);
        }

        Font font = (Font) model.getValue(modelRow, ColorFontChooserPropertyResolver.FONT_PN);
        if(font != null) {
            component.setFont(font);
        }

        Integer fontStyle = (Integer) model.getValue(modelRow, ColorFontChooserPropertyResolver.FONT_STYLE_PN);
        if(fontStyle != null) {
            Font prevFont = component.getFont();
            Font newFont = new Font(prevFont.getFontName(), fontStyle, prevFont.getSize());
            component.setFont(newFont);
        }

        return component;
    }
}
